﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Nest;

namespace Infrastructure.ElasticSearch.ParentChilds
{
    public class EsSearchStringTermsQuery<T>: ISearchSpecification<ISearchRequest<T>> where T : class
    {
        private readonly List<string> _values;
        private readonly Expression<Func<T, string>> _field;

        public EsSearchStringTermsQuery(List<string> values,Expression<Func<T, string>> field)
        {
            _values = values;
            _field = field;
        }

        public bool IsNest { get; set; }
        public ISearchRequest<T> IsSatisfiedBy()
        {
            return new SearchDescriptor<T>()
                .Query(q => q
                    .Terms(m => m
                        .Field(_field)
                        .Terms(_values)
                    )
                );
        }
    }
}